//app.js
App({
  globalData: {
    userInfo: null,
  //  allUrl: "http://localhost:8080/JDLSP",
   // allUrl: "https://jdlsp.gstxxcx.com/JDLSP",
    allUrl: "https://pfwz.wyjzpw.com/api",
    referrerId:"",
   // imageUrl: "http://localhost:8080/JDLSP/main/",
 //   imageUrl: "https://jdlsp.gstxxcx.com/JDLSP/main/",
    imageUrl: "https://pfwz.wyjzpw.com",
  },
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    // var logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    // wx.setStorageSync('logs', logs)
  },
  onLoad: function () {

  },
  showShareMenus: function () {
    wx.showShareMenu({
      withShareTicket: true,
    })
  },
  getUserInfo: function (cb) {//获取用户的唯一 openid
    var that = this;
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function (rese) {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.hasRoot = false;
              that.globalData.noRoot = true;
              wx.setStorageSync('userInfo', res.userInfo)//将用户信息储存在本
              that.globalData.userInfo = res.userInfo;
           //   console.log(res.userInfo.nickName);
              var reg = /[A-Za - z0 - 9_\-\u4e00 - \u9fa5]+/
              if (!reg.test(res.userInfo.nickName)) {
                res.userInfo.nickName == "默认用户名"
              }
              wx.request({
                url: that.globalData.allUrl + "/login/login",
                data: {
                  code: rese.code,
                //  username: res.userInfo.nickName,
               //   headportrait: res.userInfo.avatarUrl,
               //   referrerId: that.globalData.referrerId,
                },
                method: 'POST',
                header:{},
                success: function (res) {
               //   console.log(res)
                  that.globalData.referrerId = res.data;
                  wx.setStorageSync('userid', res.data)
                }, fail: function () {
                }
              })
            }, fail: function () {
              that.globalData.hasRoot = true;
              that.globalData.noRoot = false;
            }
          })
        }
      })
    }
  }
})